package com.gpj.netty.application.netty.base;

import com.sun.corba.se.internal.CosNaming.BootstrapServer;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;

/**
 * @className NettyClient
 * @description
 *   TODO
 * @author GPJ
 * @date 2021-12-06 17:26
 * @version 1.0
 **/
@Slf4j
public class NettyClient {
	public static void main(String[] args) throws InterruptedException {
		NioEventLoopGroup group = new NioEventLoopGroup();
		Bootstrap bootstrap = new Bootstrap();
		bootstrap.group(group)
				.channel(NioSocketChannel.class)
				.handler(new ChannelInitializer<SocketChannel>() {
					@Override
					protected void initChannel(SocketChannel socketChannel) throws Exception {
						socketChannel.pipeline().addLast(new ClientHandler());
					}
				});

		log.debug("netty client starting...");

		//启动客户端去连接服务器端
		ChannelFuture cf = bootstrap.connect("127.0.0.1", 9000).sync();
		//对通道关闭进行监听
		cf.channel().closeFuture().sync();
	}
}
